package com.ap.core.jbehave;

import org.jbehave.core.configuration.Configuration;
import org.jbehave.core.configuration.MostUsefulConfiguration;
import org.jbehave.core.io.LoadFromClasspath;
import org.jbehave.core.junit.JUnitStories;
import org.jbehave.core.reporters.Format;
import org.jbehave.core.reporters.StoryReporterBuilder;
import org.jbehave.core.steps.ParameterControls;

/**
 * Ancestral Story class used to provide configurations and a story context.
 */
public abstract class CommonStories extends JUnitStories {

    private final StoryContext storyContext = new StoryContext();

    protected CommonStories() {
    	configuredEmbedder().embedderControls().doIgnoreFailureInView(true).useStoryTimeoutInSecs(3000);
    }

    @Override
    public Configuration configuration() {
        return new MostUsefulConfiguration()
                .useParameterControls(new ParameterControls().useDelimiterNamedParameters(true))
                .useStoryLoader(new LoadFromClasspath(this.getClass()))
                .useStoryReporterBuilder(new StoryReporterBuilder().withDefaultFormats().withFormats(Format.CONSOLE, Format.TXT, Format.XML));
    }

    /**
     * This method returns a com.ap.core.common story context that can be shared by all the steps that is cleared before every story.
     * @return a shareable story context.
     */
    public StoryContext storyContext() {
        return storyContext;
    }
}
